package controller.listener.menu;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import model.MenuModel;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

import configuration.Configuration;

import business.ViewLogger;

import utils.FileUtils;
import utils.ListFileOfDirectory;
import view.MainMenu;
import view.ViewUtils;

public class UtidListener extends MenuCommonListener implements SelectionListener {

	/**
	 * 
	 * @param _model
	 * @param _view
	 */
	public UtidListener(MenuModel _model, MainMenu _view) {
		super(_model, _view);
		
	}

	/**
	 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
	 */
	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
		// TODO Auto-generated method stub

	}

	/**
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
	 */
	@Override
	public void widgetSelected(SelectionEvent arg0) {
		String bdPath = ViewUtils.getInstance().fileDialog("Ruta Base de datos", "Seleccione el fichero mdb que contenga la tabla TratamientoDoc", "*.mdb");
		
		if (!bdPath.isEmpty() && FileUtils.exists(bdPath)) {
					ArrayList<File> listFiles;
					HashMap<String,String> beansDb = new HashMap<String,String>();
					beansDb.put("HtmlUnitDataSource", getPath("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=", bdPath));
					String bool="false";
					if (_model.changeDatabases(beansDb)){
						_model.RetrieveUtid();
					}else {ViewLogger.getInstance().error("No se han podido cambiar las rutas de las bases de datos");}
				
		}else{
			ViewLogger.getInstance().error("Error al seleccionar ruta del fichero .mdb");
		}

	}

}
